package cn.gok.reflect;
import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
import java.lang.reflect.Method;

/**
 * @ClassName class类例子
 * @Description TODO
 * @Author HP
 * @Date 11:34 2022/7/12
 * @Version 1.0
 **/
interface Fly{
    void fly();
}
class A implements Fly{
    private int x;
    private int y;
    public A() {

    }

    private void test(){};

    public A(int x) {
        this.x = x;
    }

    public int getX() {
        return x;
    }

    public void setX(int x) {
        this.x = x;
    }

    @Override
    public void fly() {
        System.out.println(this.x+"在飞");
    }
    private void doTest(String str,Float f){
        System.out.println("这是私有方法"+str+f);
    }

}
class B extends A{
    public B() {
    }

    public B(int x) {
        super(x);
    }

    @Override
    public void fly() {
        System.out.println("B在飞");
    }

}

public class class类例子 {
    public static void main(String[] args) throws ClassNotFoundException, NoSuchMethodException, NoSuchFieldException {
        class类的加载();
        获取类的信息();
    }

    private static void 获取类的信息() throws NoSuchMethodException, NoSuchFieldException {
        Class c =A.class;
        for (Method m:c.getDeclaredMethods()){
            System.out.println(m.getName()+m.getParameterCount()+m.getReturnType().getName()+m.getModifiers());
        }

        Method m2 = c.getDeclaredMethod("setX",int.class);
        for (Constructor con:c.getConstructors()){
            System.out.println(con);
            System.out.println("+++++++++++++++++++++++++");
        }


        Constructor con2 = c.getConstructor(int.class);
        System.out.println(con2);

      for (Class i:c.getInterfaces()) {
          System.out.println(i.getName()+i.getDeclaredMethods());
      }

        System.out.println(c.getName()+"  "+c.getSimpleName());

        System.out.println("------------------------------------");

        for (Field field:c.getDeclaredFields()){
          System.out.println(field);
      }
        Field field = c.getField("x");
        System.out.println(field);
    }

    private static void class类的加载() throws ClassNotFoundException {
        Class c1 = Class.forName("cn.gok.reflect.A");

        Class c2 = A.class;
        Class c3 = new A().getClass();

        System.out.println(c1==c2);
        System.out.println(c2==c3);



    }


}
